package com.lw.springmvc.servlet;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Administrator
 * @version 1.0
 * @description:
 * @date 2022/3/8 8:29
 */
@Controller
@RequestMapping("/test")
public class TestController {

    //返回结果，通过response返回
    @RequestMapping("/test1")
    public void test1(String name, HttpServletResponse response){
        response.setContentType("text/html;charset=utf-8");
        try {
            response.getWriter().write("收到的数据是===>"+name);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //返回结果
    //返回值是string类型时，默认转发
    @RequestMapping("/test2")
    public String test2(String name, HttpServletRequest request){
        return "test1?name="+name+"test2";
    }

    @RequestMapping("/test3")
    public String test3(String name, HttpServletRequest request){
        return "test1?name="+name+"test2";
    }

    @RequestMapping("/test4")
    public String test4(String name, HttpServletRequest request){
        return "forward:/test/test1";
    }
}
